/**
 * \file PluginManager.cpp
 * \brief PluginManager definition class
 * \author Edouard ROGE
 * \date 16 March 2013
 */

#include "PluginManager.h"

namespace Core
{
	namespace Plugin
	{
		PluginManager::PluginManager()
		{
			m_Plugins.resize(Count);
			for (uint32 i = 0; i < Count; ++i)
				m_Plugins[i] = NULL;
		}

		PluginManager::~PluginManager()
		{

		}

		error PluginManager::UnregisterPlugin(Type _ePluginType)
		{
			if (m_Plugins[_ePluginType] == NULL)
			{
				LOG_ERROR("Cannot unload plug-in");
				return errFailed;
			}

			m_Plugins[_ePluginType]->Unload();
			delete m_Plugins[_ePluginType];
			m_Plugins[_ePluginType] = NULL;

			return errOK;
		}

		Plugin * PluginManager::GetPlugin(Type _ePluginType) const
		{
			return m_Plugins[_ePluginType];
		}

		IPlugin * PluginManager::GetPluginInterface(Type _ePluginType) const
		{
			return GetPlugin(_ePluginType)->GetInterface();
		}
	}
}